// ml:run = $bin < input
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

struct data { int cost; long long value; };

bool operator<(data const& a, data const& b)
{
    return a.cost < b.cost;
}

int n, lim;

int main()
{
    std::ios_base::sync_with_stdio(false);
    while (std::cin >> n >> lim) {
        std::vector<data> da;
        for (int i = 0; i < n; i++) {
            data tmp;
            std::cin >> tmp.cost >> tmp.value;
            if (tmp.cost > lim) continue;
            da.push_back(tmp);
        }
        n = da.size();

        std::sort(da.begin(), da.end());

        std::map<int, long long> dp;
        dp[0] = 0;
        long long ans = 0;
        for (int i = 0; i < n; i++) {
            std::vector<data> tmp;
            for (auto it : dp) {
                if (it.first + da[i].cost > lim) break;
                if (it.second + da[i].value > dp[it.first + da[i].cost]) {
                    tmp.push_back({it.first + da[i].cost, it.second + da[i].value});
                    ans = std::max(ans, it.second + da[i].value);
                }
            }
            for (auto it : tmp)
                dp[it.cost] = std::max(dp[it.cost], it.value);
        }
        std::cout << ans << "\n";
    }
}

